/*     */ package com.yss.sofa.cml.color;
/*     */ 
/*     */ import com.yss.sofa.cml.CloneableObject;
/*     */ import com.yss.sofa.cml.SerializableObject;
/*     */ 
/*     */ public class Color
/*     */   implements Transparency, SerializableObject, CloneableObject<Color>
/*     */ {
/*     */   private static final long serialVersionUID = 1L;
/*  15 */   public static final Color GRAY = new Color(190, 190, 190);
/*  16 */   public static final Color BLACK = new Color(0, 0, 0);
/*  17 */   public static final Color WHITE = new Color(255, 255, 255);
/*  18 */   public static final Color RED = new Color(255, 0, 0);
/*     */   private int value;
/*     */ 
/*     */   public Color(int red, int green, int blue)
/*     */   {
/*  23 */     this(red, green, blue, 255);
/*     */   }
/*     */ 
/*     */   public Color(int red, int green, int blue, int alpha) {
/*  27 */     validateColor(red, green, blue, alpha);
/*  28 */     this.value = ((alpha & 0xFF) << 24 | (red & 0xFF) << 16 | (green & 0xFF) << 8 | (blue & 0xFF) << 0);
/*     */   }
/*     */ 
/*     */   public void setRGB(int red, int green, int blue) {
/*  32 */     validateColor(red, green, blue, 255);
/*  33 */     this.value = (0xFF000000 | (red & 0xFF) << 16 | (green & 0xFF) << 8 | (blue & 0xFF) << 0);
/*     */   }
/*     */ 
/*     */   public void setValue(int value) {
/*  37 */     this.value = value;
/*     */   }
/*     */ 
/*     */   public Color(int rgb) {
/*  41 */     this.value = (0xFF000000 | rgb);
/*     */   }
/*     */ 
/*     */   private void validateColor(int red, int green, int blue, int alpha) {
/*  45 */     String badComponentString = "";
/*  46 */     boolean rangeError = false;
/*  47 */     if ((alpha < 0) || (alpha > 255)) {
/*  48 */       rangeError = true;
/*  49 */       badComponentString = badComponentString + " Alpha(0-255), fact is " + alpha;
/*     */     }
/*  51 */     if ((red < 0) || (red > 255)) {
/*  52 */       rangeError = true;
/*  53 */       badComponentString = badComponentString + " Red(0-255), fact is " + red;
/*     */     }
/*  55 */     if ((green < 0) || (green > 255)) {
/*  56 */       rangeError = true;
/*  57 */       badComponentString = badComponentString + " Green(0-255), fact is " + green;
/*     */     }
/*  59 */     if ((blue < 0) || (blue > 255)) {
/*  60 */       rangeError = true;
/*  61 */       badComponentString = badComponentString + " Blue(0-255), fact is " + blue;
/*     */     }
/*  63 */     if (rangeError == true)
/*  64 */       throw new IllegalArgumentException("RGB Color parameter outside of expected range:" + badComponentString);
/*     */   }
/*     */ 
/*     */   public int getRed()
/*     */   {
/*  73 */     return getRGB() >> 16 & 0xFF;
/*     */   }
/*     */ 
/*     */   public int getGreen()
/*     */   {
/*  81 */     return getRGB() >> 8 & 0xFF;
/*     */   }
/*     */ 
/*     */   public int getBlue()
/*     */   {
/*  89 */     return getRGB() >> 0 & 0xFF;
/*     */   }
/*     */ 
/*     */   public int getAlpha()
/*     */   {
/*  97 */     return getRGB() >> 24 & 0xFF;
/*     */   }
/*     */ 
/*     */   public int getRGB()
/*     */   {
/* 105 */     return this.value;
/*     */   }
/*     */ 
/*     */   public int getTransparency()
/*     */   {
/* 113 */     int alpha = getAlpha();
/* 114 */     if (alpha == 255)
/* 115 */       return 1;
/* 116 */     if (alpha == 0) {
/* 117 */       return 2;
/*     */     }
/* 119 */     return 3;
/*     */   }
/*     */ 
/*     */   public static Color decode(String hexColor)
/*     */   {
/* 124 */     Integer intval = Integer.decode(hexColor);
/* 125 */     int i = intval.intValue();
/* 126 */     return new Color(i >> 16 & 0xFF, i >> 8 & 0xFF, i & 0xFF);
/*     */   }
/*     */ 
/*     */   public String toString() {
/* 130 */     return "Color[r=" + getRed() + ",g=" + getGreen() + ",b=" + getBlue() + "]";
/*     */   }
/*     */ 
/*     */   public int hashCode() {
/* 134 */     return this.value;
/*     */   }
/*     */ 
/*     */   public boolean equals(Object obj) {
/* 138 */     if (obj == null) {
/* 139 */       return false;
/*     */     }
/* 141 */     if ((obj instanceof Color)) {
/* 142 */       return ((Color)obj).value == this.value;
/*     */     }
/* 144 */     return false;
/*     */   }
/*     */ 
/*     */   public Color clone() {
/* 148 */     Color clone = null;
/*     */     try {
/* 150 */       clone = (Color)super.clone();
/*     */     } catch (CloneNotSupportedException e) {
/* 152 */       throw new RuntimeException(e);
/*     */     }
/* 154 */     return clone;
/*     */   }
/*     */ }

/* Location:           X:\repository\com\yss\sofa\cml\cml-api\1.1.0\cml-api-1.1.0.jar
 * Qualified Name:     com.yss.sofa.cml.color.Color
 * JD-Core Version:    0.6.0
 */